package com.magicalcoder.pigeontest.service.impl;

import com.magicalcoder.pigeon.ioc.anotation.Service;
import com.magicalcoder.pigeon.mysql.manager.ConnectionManager;
import com.magicalcoder.pigeon.mysql.manager.DbConnection;
import com.magicalcoder.pigeon.mysql.manager.execute.Execute;
import com.magicalcoder.pigeon.mysql.manager.execute.ExecuteSql;

import java.util.List;

/**
 * Created by hzhedongyu on 2017/6/15.
 */

@Service("connectionManagerTemplate")
public class ConnectionManagerTemplateImpl implements ConnectionManagerTemplate{

    private ConnectionManager connectionManager;

    @Override
    public void setConnectionManager(ConnectionManager connectionManager) {
        this.connectionManager = connectionManager;
    }

    public <T> List<T> selectList(String sql, Class<T> clazz){
        DbConnection dbConnection = connectionManager.acquireCon();
        Execute executeSql = new ExecuteSql(dbConnection);
        try {
            return executeSql.selectList(sql,clazz);
        }finally {
            executeSql.release();
        }
    }
}
